/**
 * File:		RequestInterpreter.java
 * Project:		Virtual Advisor
 * Module:		Data Management
 * Author:		Rotem Ganel
 * Created:		April 15, 2011
 * Updated:		April 30, 2011
 * Version:		1 (in progress)
 */
package server.dataManagement;

import java.awt.Desktop.Action;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import clientApp.*;
import clientApp.Section.REQ_TYPE;
//import server.appObjects.*;
//import server.appObjects.Section.REQ_TYPE;
import server.dataManagement.Queries.AdminQuery;
import server.dataManagement.Queries.CourseQuery;
import server.dataManagement.Queries.DegreeQuery;
import server.dataManagement.Queries.PlanQuery;
import server.dataManagement.Queries.Query;
import server.dataManagement.Queries.RecordQuery;
import server.dataManagement.Queries.SectionQuery;
import server.dataManagement.Queries.SemesterQuery;
import server.dataManagement.Queries.SeriesQuery;
import server.dataManagement.Queries.StudentQuery;
import server.dataManagement.Queries.SubsectionQuery;
import server.dataManagement.Queries.UserTypeQuery;
import server.dataManagement.Queries.Query.ACTION;
import server.dataManagement.exceptions.*;

public class RequestInterpreter {

	/**
	 * Name: 
	 * Description: 
	 * PreCondition:  
	 * PostCondition: 
	 * Parameters:
	 * Notes:
	 */
	public static void setFilenames(String catalogFile, String curriculumFile, String userFile) {
		XMLHandler.setFilenames(catalogFile, curriculumFile, userFile);
	}
	
	public static String[] getFilenames() throws RepositoryFilenamesNotSetException {
		return XMLHandler.getFilenames();
	}
	
	public static boolean filenamesSet() {
		return XMLHandler.filenamesSet();
	}

	public static ArrayList<Course> retrieveCatalog() throws IOException, RepositoryFilenamesNotSetException {
		ArrayList<Course> courses = new ArrayList<Course>();
		String[] courseIDs = XMLHandler.InventoryCatalog(), fields;
		Query q;

		for (int i = 0; i < courseIDs.length; i++) {
			q = new CourseQuery(ACTION.Read, courseIDs[i]);
			XMLHandler.query(q);
		
			fields = q.review();
			courses.add(createCourse(fields));
		}		
	
		return courses;
	}
	
	private static Course createCourse(String[] fields) {
		String ID, name, description;
		String[] prerequisites;
		int[] availability;
		double credits;
		
		ID = fields[0];
		name = fields[1];
		description = "This is a description.";
		
		if (fields[4].indexOf(", ") != -1) {
			prerequisites = fields[4].split(", ");
		} else {
			prerequisites = new String[]{"none"};
		}
		
		String[] avail = fields[2].split(", ");
		availability = new int[avail.length];
		for (int j = 0; j < avail.length; j++) {
			availability[j] = ProjectConstants.getDegreeInt(avail[j]);
		}

		credits = Double.parseDouble(fields[3]);

		return new Course(ID, name, description, prerequisites, availability, credits);
	}
	
	public static ArrayList<User> getAllTheFuckinUsers() throws RepositoryFilenamesNotSetException, IOException {
		String[] users = XMLHandler.InventoryUsernames();
		ArrayList<User> theUsers = new ArrayList<User>();
		
		for (String u : users) {
			User user = findUser(u);
			if (user != null) {
				theUsers.add(user);
			}
		}
		
		return theUsers;
	}
	
	private static User findUser(String username) throws IOException {
		if (getUserType(username) == 1) {
			return findStudent(username);
		} else if (getUserType(username) == 0) {
			return findAdmin(username);
		} else {
			return null;
		}
	}
	
	public static User findUser(String username, String password) throws IOException {				
		if (getUserType(username) == 1) {
			return findStudent(username, password);
		} else if (getUserType(username) == 0) {
			return findAdmin(username, password);
		} else {
			return null;
		}
	}
	
	public static int getUserType(String username) throws IOException {
		Query user = new UserTypeQuery(ACTION.Read, username);
		XMLHandler.query(user);
		String response = user.review()[0];
		
		if (response.equals("Admin")) {
			return 0;
		} else if (response.equals("Student")) {
			return 1;
		} else {
			return -1;
		}
	}
	
	public static void saveUsers(ArrayList<User> users) {
		//TODO: stub
	}

	private static AdminQuery packageAdmin(Admin admin) {
		AdminQuery query = new AdminQuery(ACTION.Create, admin.getUsername());
		query.respond(new String[]{admin.getPassword(), admin.getName()});

		return query;
	}

	private static void packageStudent(Student student) {
		//TODO: stub
	}
	
	private static void packagePlan(Plan plan) {
		//TODO: stub
	}

	private static void packageSemester(Semester semester) {
		
		
		//TODO: stub
	}
	
	private static RecordQuery packageRecord(CourseRecord record) {
		RecordQuery query = new RecordQuery(ACTION.Create, record.getCourseID());
		query.respond(new String[]{Character.toString(record.getGrade()), record.getNotes()});
		
		return query;
	}
	
	private static Admin findAdmin(String username, String givenPass) throws IOException {
		Query admin = new AdminQuery(ACTION.Read, username);
		XMLHandler.query(admin);
		String[] adminResponse = admin.review();
		
		if (!(adminResponse[1]).equals(givenPass)) {
			return null;
		}
		
		String name = adminResponse[2];
	
		return new Admin(username, givenPass, name);
	}
	
	private static Student findStudent(String username) throws IOException {
		Query student = new StudentQuery(ACTION.Read, username);
		XMLHandler.query(student);
		
		//OMG HARDCORE HAXX
		return findStudent(username, student.review()[1]);
	}
	
	private static Admin findAdmin(String username) throws IOException {
		Query admin = new AdminQuery(ACTION.Read, username);
		XMLHandler.query(admin);
		
		//OMG HARDCORE HAXX
		return findAdmin(username, admin.review()[1]);
	}
	
	
	private static Student findStudent(String username, String givenPass) throws IOException {
		Query student = new StudentQuery(ACTION.Read, username);
		Query plan, semester, record;
		XMLHandler.query(student);
		String[] studentResponse = student.review();
		
		if (!(studentResponse[1]).equals(givenPass)) {
			return null;
		}

		ArrayList<Plan> plans = new ArrayList<Plan>();
		ArrayList<Semester> semesters = new ArrayList<Semester>();
		ArrayList<CourseRecord> records = new ArrayList<CourseRecord>();
		
		//Plan query components
		String[] planNames = studentResponse[4].split(", ");
		String[] planResponse;

		//Semester query components
		String[] dates;
		String[] semesterResponse;

		//Record query components
		String[] courses;
		String[] recordResponse;
		
		for (String planName : planNames) {			
			//Construct plan
			plan = new PlanQuery(ACTION.Read, planName);
			XMLHandler.query(plan);
			planResponse = plan.review();
			dates = planResponse[1].split(", ");
			
			for (String semesterDate : dates) {
				//Construct semester
				semester = new SemesterQuery(ACTION.Read, semesterDate);
				XMLHandler.query(semester);
				semesterResponse = semester.review();
				courses = semesterResponse[2].split(", ");
				
				for (String courseID : courses) {
					//Construct courseRecord
					record = new RecordQuery(ACTION.Read, courseID);
					XMLHandler.query(record);
					recordResponse = record.review();
					
					records.add(createRecord(recordResponse));
				}
				
				semesters.add(createSemester(semesterResponse, records));
				records.clear();
			}
			
			plans.add(createPlan(planResponse, semesters));
			semesters.clear();
		}
				
		return createStudent(studentResponse, plans);
	}

	private static Student createStudent(String[] fields, ArrayList<Plan> plans) {
		String username = fields[0], password = fields[1], name = fields[2];
		int degree = Integer.parseInt(fields[3]);
				
		return new Student(username, password, name, degree, plans);
	}
	
	private static Plan createPlan(String[] fields, ArrayList<Semester> semesters) {
		String name = fields[0];

		return new Plan(name, semesters);
	}
	
	private static Semester createSemester(String[] fields, ArrayList<CourseRecord> courses) {
		String[] date = fields[0].split(" ");
		String strOverride = fields[1];
		boolean override;
		int season, year;
		
		if (strOverride.equals("true")) {
			override = true;
		} else {
			override = false;
		}
		
		season = ProjectConstants.getSeasonInt(date[0]);		
		year = Integer.parseInt(date[1]);

		return new Semester(season, year, override, courses);
	}
	
	private static CourseRecord createRecord(String[] fields) {		
		String courseID = fields[0], notes = fields[2];
		char grade = fields[1].charAt(0);
		
		return new CourseRecord(courseID, grade, notes);
	}

	public static ArrayList<String> getDegreeIDs() {
		return null;
	}
	
	public static ArrayList<Degree> getDegrees() throws IOException {
		ArrayList<Degree> programs = new ArrayList<Degree>();
		programs.add(createDegree("CSM"));
		programs.add(createDegree("CSMn"));
		programs.add(createDegree("ISM"));
		programs.add(createDegree("GEP"));
		
		return programs;
	}

	private static Degree createDegree(String ID) throws IOException {
		DegreeQuery d = new DegreeQuery(ACTION.Read, ID);
		XMLHandler.query(d);
		String[] degreeResponse = d.review();

		Degree degree = new Degree(degreeResponse[1]);
		String[] sectionIDs = degreeResponse[2].split(", ");
		String[] sectionNames = degreeResponse[3].split(", ");
		for (int i = 0; i < sectionIDs.length; i++) {
			createSection(degree, sectionIDs[i], sectionNames[i]);
		}
		
		return degree;
	}
	
	private static Section createSection(Degree degree, String sectionID, String sectionName) throws IOException {
		degree.addSection(sectionName);

		SectionQuery s = new SectionQuery(ACTION.Read, sectionID);
		XMLHandler.query(s);
		String[] sectionResponse = s.review();
				
		REQ_TYPE reqType = REQ_TYPE.INVALID;
		
		if (sectionResponse[2].equals("Take All")) {
			reqType = REQ_TYPE.Take_All;
		} else if (sectionResponse[2].equals("Take X Credits")) {
			reqType = REQ_TYPE.Take_X_Creds;
		} else if (sectionResponse[2].equals("XOR")) {
			reqType = REQ_TYPE.XOR;
		} else if (sectionResponse[2].equals("Take Any")) {
			reqType = REQ_TYPE.Take_Any;
		} else if (sectionResponse[2].equals("Take X Courses")) {
			reqType = REQ_TYPE.Take_X_Courses;
		}
		
		int unitsNeeded = Integer.parseInt(sectionResponse[3]);
		degree.setUnitsNeeded(sectionName, unitsNeeded);
		degree.setReqType(sectionName, reqType);

		Section section = degree.getSection(sectionName);
		
		for (String subsection : sectionResponse[4].split(", ")) {
			createSubsection(section, subsection);
		}

		return section;
	}
	
	private static void createSubsection(Section section, String subsectionID) throws IOException {
		SubsectionQuery s = new SubsectionQuery(ACTION.Read, subsectionID);
		XMLHandler.query(s);
		String[] subsectionResponse = s.review();
		
		REQ_TYPE reqType = REQ_TYPE.INVALID;
		
		if (subsectionResponse[2].equals("Take All")) {
			reqType = REQ_TYPE.Take_All;
		} else if (subsectionResponse[2].equals("Take X Credits")) {
			reqType = REQ_TYPE.Take_X_Creds;
		} else if (subsectionResponse[2].equals("XOR")) {
			reqType = REQ_TYPE.XOR;
		} else if (subsectionResponse[2].equals("Take Any")) {
			reqType = REQ_TYPE.Take_Any;
		} else if (subsectionResponse[2].equals("Take X Courses")) {
			reqType = REQ_TYPE.Take_X_Courses;
		}
		
		int unitsNeeded = Integer.parseInt(subsectionResponse[3]);
		
		section.addSubsection(reqType, unitsNeeded);
		int actualSubsection = section.numSubsections();
		String[] courseDetails = subsectionResponse[4].split(", ");
		
		createAllSeries(section, actualSubsection, courseDetails);
	}
	
	private static void createAllSeries(Section section, int subsectionID, String[] courseDetails) throws IOException {
		SeriesQuery s;
		String[] seriesResponse, series, courseIDs;
		char[] gradeNeeded;
		boolean[] honors;
		
		ArrayList<String> courses = new ArrayList<String>();
		for (String course : courseDetails) {
			courses.add(course);
		}
				
		while (courses.size() != 0) {
			s = new SeriesQuery(ACTION.Read, courses.get(0));
			XMLHandler.query(s);
			seriesResponse = s.review();
			
			//parse course segments
			series = seriesResponse[0].split(", ");
			courseIDs = new String[series.length];
			gradeNeeded = new char[series.length];
			honors = new boolean[series.length];
			for (int i = 0; i < series.length; i++) {
				courseIDs[i] = parseString(series[i], "\"", "\"");
				gradeNeeded[i] = parseString(series[i], "grade=\"", "\"").charAt(0);
				if (parseString(series[i], "honors=\"", "\"").equals("true")) {
					honors[i] = true;
				} else {
					honors[i] = false;
				}
				
				courses.remove(series[i]);
			}

			section.addNewReqSeriesToSubsection(subsectionID, courseIDs, gradeNeeded, honors);
		}		
	}
	
	private static String parseString(String entry, String beginFlag, String endFlag) {
		int beginIndex = entry.indexOf(beginFlag) + beginFlag.length();
		int endIndex = entry.indexOf(endFlag, beginIndex);
		
		if ((beginIndex != -1) && (endIndex != -1)) {
			return entry.substring(beginIndex, endIndex);
		} else {
			return null;
		}
	}
	
	public static void haxx(ArrayList<User> users) throws IOException {
		Date today = new Date();
		String formattedDate = "MM/dd/yy";
		SimpleDateFormat formatter = new SimpleDateFormat(formattedDate);
		formattedDate = formatter.format(today);
		
		String write = "<users updated=\"" + formattedDate + "\">\n";
		Student s = new Student(write, write, write, 0);
		Admin a;
		
		for (User u : users) {
			if (u.getClass().equals(s.getClass())) {
				s = (Student)u;
				
				write += "\t<student username=\"" + s.getUsername() + "\">\n";
				write += "\t\t<password>" + s.getPassword() + "</password>\n";
				write += "\t\t<name>" + s.getName() + "</name>\n";
				write += "\t\t<program id=\"" + s.getDegree() + "\" />\n";
				write += "\t\t<plans>\n";
				
				for (Plan p : s.getPlans()) {
					write += "\t\t\t<schedule name=\"" + p.getPlanName() + "\">\n";
					
					for (Semester m : p.getSemesters()) {
						write += "\t\t\t\t<semester date=\"" + ProjectConstants.getSeasonString(m.getSeason()) + " " + m.getYear() + "\">\n";
						write += "\t\t\t\t\t<override>" + m.isOverridden() + "</override>\n";
						write += "\t\t\t\t\t<course_load>\n";
						
						for (CourseRecord r : m.getCourseRecords()) {
							write += "\t\t\t\t\t\t\t<record id=\"" + r.getCourseID() + "\">\n";
							write += "\t\t\t\t\t\t\t\t<grade>" + r.getGrade() + "</grade>\n";
							write += "\t\t\t\t\t\t\t\t<notes>" + r.getNotes() + "</notes>\n";
							write += "\t\t\t\t\t\t\t</record>\n";
						}
						
						write += "\t\t\t\t\t</course_load>\n";
						write += "\t\t\t\t</semester>\n";
					}
					
					write += "\t\t\t</schedule>\n";
				}
				
				write += "\t\t</plans>\n";
				write += "\t</student>\n";
			} else {
				a = (Admin)u;
				
				write += "\t<admin username=\"" + a.getUsername() + "\">\n";
				write += "\t\t<password>" + a.getPassword() + "</password>\n";
				write += "\t\t<name>" + a.getName() + "</name>\n";
				write += "\t</admin>\n";
			}
		}
		
		write += "</users>";
		
		XMLHandler.hax(write, "Users.xml");
	}
	
	public static void storeCatalog(ArrayList<Course> catalog) throws IOException {
		Date today = new Date();
		String formattedDate = "MM/dd/yy";
		SimpleDateFormat formatter = new SimpleDateFormat(formattedDate);
		formattedDate = formatter.format(today);
		
		String write = "<catalog updated=\"" + formattedDate + "\">\n";
		
		for (Course c : catalog) {
			write += "\t<course ID=\"" + c.getCourseCode() + "\">\n";
			write += "\t\t<name>" + c.getCourseName() + "</name>\n";
			write += "\t\t<availability>\n";
			
			for (int season : c.getAvailability()) {
				write += "\t\t\t<semester season=\"" + ProjectConstants.getSeasonString(season) + "\" />\n";
			}
			
			write += "\t\t</availability>\n";
			write += "\t\t<credits>" + c.getNumCreds() + "</credits>\n";
			write += "\t\t<requirements>\n";
			
			for (String s : c.getPrereqs()) {
				write += "\t\t\t<prerequisite reference=\"" + s + "\" />\n";
			}
			
			write += "\t\t</requirements>\n";
			write += "\t</course>\n";
		}
		
		write += "</catalog>";
		
		XMLHandler.hax(write, "Catalog.xml");
	}
	
	public static void storeCurriculum(ArrayList<Degree> curriculum) throws IOException {
		Date today = new Date();
		String formattedDate = "MM/dd/yy";
		SimpleDateFormat formatter = new SimpleDateFormat(formattedDate);
		formattedDate = formatter.format(today);
		
		String write = "<curriculum updated=\"" + formattedDate + "\">\n";
		
		char sID = 'A';
		int bID = 1;
		for (Degree d : curriculum) {
			String id = "";
			if (d.name.equals("Computer Science Major")) {
				id = "CSM";
			} else if (d.name.equals("Computer Science Minor")) {
				id = "CSMn";
			} else if (d.name.equals("Information Systems Major")) {
				id = "ISM";
			} else if (d.name.equals("General Education Program")) {
				id = "GEP";
			}
			
			write += "\t<program id=\"" + id + "\">\n";
			write += "\t\t<name>" + d.name + "</name>\n";
			write += "\t\t<segments>\n";
			
			for (Section s : d.getSections()) {
				write += "\t\t\t<section id=\"" + sID + "\">\n";
				sID++;
				write += "\t\t\t\t<name>" + s.name + "</name>\n";
				write += "\t\t\t\t<requirement type=\"" + s.getReqType().toString().replace("_", " ") + "\" />\n";
				write += "\t\t\t\t<units needed=\"" + s.getUnitsNeeded() + "\" />\n";
				write += "\t\t\t\t<subsegments>\n";
				
				for (int i = 1; i <= s.numSubsections(); i++) {
					write += "\t\t\t\t\t<subsection id=\"" + bID + "\">\n";
					bID++;
					write += "\t\t\t\t\t\t<requirement type=\"" + s.getReqTypeBySubsection(i).toString().replace("_", " ") + "\" />\n";
					write += "\t\t\t\t\t\t<units needed=\"" + s.getUnitsNeededBySubsection(i) + "\" />\n";
					write += "\t\t\t\t\t\t<options>\n";
					
					for (String[] sequence : s.getCoursesInSubsection(i)) {
						write += "\t\t\t\t\t\t\t<series>\n";
						
						for (String course : sequence) {
							write += "\t\t\t\t\t\t\t\t<course id=\"" + course + "\"";
							write += " grade=\"" + s.getGradeNeeded(course) + "\"";
							write += " honors=\"" + s.getHonors(course) + "\" />\n";
						}
						
						write += "\t\t\t\t\t\t\t</series>\n";
					}
					
					write += "\t\t\t\t\t\t</options>\n";
					write += "\t\t\t\t\t</subsection>\n";
				}
				
				write += "\t\t\t\t</subsegments>\n";
				write += "\t\t\t</section>\n";
			}
			
			write += "\t\t</segments>\n";
			write += "\t</program>\n";
		}
		
		write += "</curriculum>";

		XMLHandler.hax(write, "Curriculum.xml");
	}

	
	public static void main(String[] args) {	
		/*
		RequestInterpreter.setFilenames("Catalog.xml", "Curriculum.xml", "Users.xml");
		Query q;
		String[] fields;
		String ID, name, description;
		String[] prerequisites;
		int[] availability;
		int credits;
		
		
		*/
		try {/*
			//Get all course IDs from catalog
			String[] courseIDs = XMLHandler.InventoryCatalog();

			System.out.println("All Courses");
			for (int i = 0; i < courseIDs.length; i++) {
				q = new CourseQuery(Query.ACTION.Read, courseIDs[i]);
				XMLHandler.query(q);
			
				fields = q.review();
				
				ID = fields[0];
				name = fields[1];
				description = "This is a description.";
				
				if (fields[4].indexOf(", ") != -1) {
					prerequisites = fields[4].split(", ");
				} else {
					prerequisites = new String[]{"none"};
				}
				
				String[] avail = fields[2].split(", ");
				availability = new int[avail.length];
				for (int j = 0; j < avail.length; j++) {
					if (avail[j].equals("Fall")) {
						availability[j] = ProjectConstants.FALL;
					} else if (avail[j].equals("Winter")) {
						availability[j] = ProjectConstants.WINTER;
					} else if (avail[j].equals("Spring")) {
						availability[j] = ProjectConstants.SPRING;
					} else if (avail[j].equals("Summer")) {
						availability[j] = ProjectConstants.SUMMER;
					}
				}

				credits = Integer.parseInt(fields[3]);

				Course c = new Course(ID, name, description, prerequisites, availability, credits);
				System.out.println(c);
			}
			*/
			//Get all users
/*			String[] usernames = XMLHandler.InventoryUsernames();
			String[] passwords = {"pass2", "pass1", "test"};
						
			User u;
			Student s;
			Admin a;
			ArrayList<Plan> plans;
			ArrayList<Semester> semesters;
			ArrayList<CourseRecord> records;
			
			System.out.println("All Users");
			for (int i = 0; i < usernames.length; i++) {
				u = RequestInterpreter.findUser(usernames[i], passwords[i]);
				if (u == null) {
					continue;
				}

				System.out.println("\nUsername: " + u.getUsername());
				System.out.println("Password: " + u.getPassword());
				System.out.println("Name: " + u.getName());
				
				if (RequestInterpreter.getUserType(usernames[i]) == 1) {
					System.out.println("Student");
					s = (Student)u;
					
					System.out.println("Degree: " + ProjectConstants.getDegreeString(s.getDegree()));
					
					plans = s.getPlans();
					for (Plan p : plans) {
						System.out.println("Plan: " + p.getPlanName());
						
						semesters = p.getSemesters();
						for (Semester semester : semesters) {
							System.out.println("\tSemester: " + ProjectConstants.getSeasonString(semester.getSeason()) + " " + semester.getYear());
							
							records = semester.getCourseRecords();
							for (CourseRecord r : records) {
								System.out.println("\t\tCourse: " + r.getCourseID());
								System.out.println("\t\t\tGrade: " + r.getGrade());
								System.out.println("\t\t\tNotes: " + r.getNotes());
							}
						}
					}
					

					System.out.println();
				} else {
					System.out.println("Admin");
					a = (Admin)u;
				}
			}*//*
			RequestInterpreter.setFilenames("Catalog.xml", "Curriculum.xml", "Users.xml");
		
			ArrayList<Degree> programs = getDegrees();
			for (Degree program : programs) {
				System.out.println("\n" + program.name);
				
				for (String sectionName : program.listSections()) {
					Section section = program.getSection(sectionName);
					System.out.println(section.name);
					System.out.println(section.getReqType());
					
					for (int i = 1; i <= section.numSubsections(); i++) {
						System.out.println("\tSubsection " + i);
						System.out.println("\t" + section.getReqTypeBySubsection(i));
						
						String[][] series = section.getCoursesInSubsection(i);
						for (String[] courseList : series) {
							System.out.print("\t\tSeries: ");
							for (String course : courseList) {
								System.out.print(course + ", ");
							}
							System.out.println();
						}
					}
				}
			}*/
			/*
			Query user = new AdminQuery(ACTION.Read, "pinkston");
			XMLHandler.query(user);
			user.action = ACTION.Create;
			XMLHandler.query(user);
			
			System.out.println();
			user = new StudentQuery(ACTION.Read, "rg5");
			XMLHandler.query(user);
			user.action = ACTION.Create;
			XMLHandler.query(user);
			*/
			/*
			System.out.println();
			Query course = new CourseQuery(ACTION.Read, "CMSC 201");
			XMLHandler.query(course);
			course.action = ACTION.Create;
			XMLHandler.query(course);
			*/

			/*
			ArrayList<Query> subqueries = new ArrayList<Query>();
			subqueries.add(new StudentQuery(ACTION.Read, "test"));
			subqueries.add(new PlanQuery(ACTION.Read, "Test plan"));
			subqueries.add(new PlanQuery(ACTION.Read, "TestLoad2"));
			for (Query q : subqueries) {
				XMLHandler.query(q);
			}
			XMLHandler.query(ACTION.Create, subqueries);		*/	
		
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
